<?
$page = "planos";
if ($_GET['id']) {
    $data = PlanosControl::Select((int) $_GET['id']);
}
?>
<script src="<?= __ADMIN_URI__; ?>js/jquery.maskMoney.js"></script>
<script src="<?= __ADMIN_URI__; ?>js/editor.js"></script>
<script>
    InitEditor(800,150);
    $(function() {    
        $("#price").maskMoney({symbol: "", decimal: ",", thousands: "."});
        $('#autoquantity').bind('keydown',soNums); // o "#input" é o input que vc quer aplicar a funcionalidade
        $('#daysamount').bind('keydown',soNums); // o "#input" é o input que vc quer aplicar a funcionalidade
    });
</script>
<div class="container-form">
    <h1>Planos de <?=ucfirst($_GET['category']);?></h1>
    <form action="<?= __ADMIN_URI__; ?>actions/<?= $page ?>.php" method="post" enctype="multipart/form-data" id="form-cadastre" onsubmit="return Validation();">
        <input type="hidden" name="redirect" id="redirect" value="<?= __ADMIN_URI__ . $page ."/". $_GET['category'] ?>">
        <input type="hidden" name="id" id="codigo" value="<?= $data[0]['id']; ?>">
        <input type="hidden" name="category" id="category" value="<?= $_GET['category']; ?>">
        <div class="input">
            Pessoa
            <select name="entitytype" id="entitytype" class="required">
                <option value=""> -- Tipo Pessoa -- </option>
                <option value="F" <? if($data[0]['entitytype']=='F' or $data[0]['entitytype']=='f'){ ?> selected="selected" <? } ?>>Física</option>
                <option value="J" <? if($data[0]['entitytype']=='J' or $data[0]['entitytype']=='j'){ ?> selected="selected" <? } ?>>Jurídica</option>
            </select>
        </div>
        <div class="input">
            Nome: <input type="text" name="name" id="name" value="<?= $data[0]['name']; ?>" class="required" size="50">
            Preço: <input type="text" name="price" id="price" value="<?= number_format($data[0]['price'],2,",","."); ?>" class="required" size="3">
            Qtd.: <input type="text" name="autoquantity" id="autoquantity" value="<?=$data[0]['autoquantity']?>" class="required" size="3" maxlength="5">
            Qtd. Dias: <input type="text" name="daysamount" id="daysamount" value="<?=$data[0]['daysamount']?>" class="required" size="3" maxlength="3">
        </div>
        <? if($_GET['category']=='veiculo'){ ?>
        <fieldset style="border:1px solid #CCC;">
            <legend>Tipo de Veículo:</legend>
            <ul class="typevehicle">
                <?
                $data_tipos = TiposControl::Listar();
                if (isset($data_tipos)) {
                    foreach ($data_tipos as $list) {
                        ?>
                        <li style="display: block;float: left;width: 160px;padding: 3px;">
                            <? $data_tipo = PlanosTiposControl::Select_Tipos($_GET['id'], $list['id']); ?>
                            <input type="checkbox" name="id_type[]" id="id_type" value="<?= $list['id']; ?>" <? if ($data_tipo[0]['id_type'] == $list['id']) { ?> checked="checked" <? } ?>>
                            <?= $list['name']; ?>
                        </li>
                        <?
                    }
                }
                ?>
            </ul>
        </fieldset>
        <? } ?>
        <div class="input">
            <textarea name="description"><?=$data[0]['description'];?></textarea>
        </div>
        <div class="input">
            <input type="submit" value="Salvar">
            <input type="button" value="Novo" onclick="location.href = $('#redirect').val();">
        </div>
    </form>
    <hr>
    <div class="list">
        <div class="list-data">
            <ul>
                <li>Cód</li>
                <li>Nome</li>
                <li>Opções</li>
            </ul>
            <?php
            if($_GET['category']=='veiculo'){
                $category = 'V';
            }else{
                $category = 'P';
            }
            foreach (PlanosControl::Listar($category) as $list) {
                $urldelete = __ADMIN_URI__ . "actions/" . $page . ".php?id=" . $list['id'] . "&redirect=" . __ADMIN_URI__ . $page."/".$_GET['category'];
                ?>
                <ul>
                    <li><?= $list['id']; ?></li>
                    <li><?= $list['name']; ?></li>
                    <li><a href="<?= __ADMIN_URI__ . $page ?>/<?= $_GET['category']; ?>/<?= $list['id']; ?>">Editar</a> | <a href="javascript:ApagarRegistro('<?= $urldelete ?>')">Excluir</a></li>
                </ul>
                <?
            }
            ?>

        </div>
    </div>
</div>

